package com.njwb.day15.zqzb.ios.io01;

import java.io.*;

public class FileInputStreamDemo01 {
    public static void main(String[] args) {
        //创建一个字节流对象 ：处理图片，处理word文档
        InputStream inputStream = null ;
        try {
            //输入流的文件必须存在
            File file = new File("e:"+File.separator+"bak.txt");
            //1、构建流
            inputStream = new FileInputStream(file);
            //读取的次数
            int count  = 0 ;
            //2、读取流的数据
            int value = 0;
            while((value= inputStream.read())!=-1) {
                //转换成字符
                char c = (char) value;
                System.out.print(c);
                count++ ;
            }
            System.out.println("\n使用read(),一共读取的次数是："+count);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {

            if(inputStream!=null) {
                //3、关闭流
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }

    }
}
